﻿/*************************************************************************
File:   as/publishCam.as
Author: Duykham
UpDate: 20/09/2006
TODO:   Get Variable from VB
/*************************************************************************/
echo("#included: getVarFromVB_S1.as");
///////////////////////////////////////////////////////////////////////////
//TODO: include files
//nothing
///////////////////////////////////////////////////////////////////////////
//TODO:ExternalInterface
import flash.external.*;
///////////////////////////////////////////////////////////////////////////
//TODO: Setup External method to be called outside of Flash
var methodSetup:Boolean = ExternalInterface.addCallback("splitCam", null, splitCam);
var methodSetup:Boolean = ExternalInterface.addCallback("setCam", null, setCam);
///////////////////////////////////////////////////////////////////////////
//TODO: variables
var camArrayVB:Array = new Array();
var soCamVB:Number = 0;
var myArray:Array = new Array();
var strVB:String = new String();
var camArr:Array = new Array();
var soCam;
//////////////////////////////////////////////////////////////////////////
//TODO:splitCam dung de tach String  do VB gui sang thanh cac chuoi nho tuong ung voi tung camera
function splitCam() {
	echo("function splitCam() ");
	soCam = strVB.charAt(strVB.lastIndexOf("<cam id=")+8);
	trace("soCam: "+soCam);
	var newStr:String = strVB;
	do {
		//thuc hien vong lap dung de tach chuoi
		var str1:String = newStr.substring(0, newStr.indexOf("</cam>")+6);
		newStr = newStr.substring(newStr.indexOf("</cam>")+6, newStr.length);
		if (str1 != undefined && str1 != "") {
			//String Str1 nhan duoc da thoa man cac dieu kien
			//co the thao tac voi no duoc roi!
			trace(str1+" ");
			//dua chuoi vao mang myArray
			camArr.push(str1);
		}
	} while (newStr != undefined && newStr != "");
}
//
function setCam() {
	echo("function setCam() ");
	for (i=0; i<soCam; i++) {
		var myString:String = camArr[i];
		var myDeviceCam:String = myString.substring(myString.indexOf("<devicecam>")+11, myString.indexOf("</devicecam>"));
		var myCamName:String = myString.substring(myString.indexOf("<camname>")+9, myString.indexOf("</camname>"));
		var myDisplayName:String = myString.substring(myString.indexOf("<displayname>")+13, myString.indexOf("</displayname>"));
		var myMotionLevel = myString.substring(myString.indexOf("<motion>")+8, myString.indexOf("</motion>"));
		var myPriority = myString.substring(myString.indexOf("<priority>")+10, myString.indexOf("</priority>"));
		camArrayVB.push({label:myCamName, data:myDeviceCam, displayName:myDisplayName, motion:myMotionLevel, priority:myPriority});
	}
	for (i=0; i<soCam; i++) {
		echo("camArrayVB: "+camArrayVB[i].data+": "+camArrayVB[i].label+": "+camArrayVB[i].displayName+": "+camArrayVB[i].motion+": "+camArrayVB[i].priority);
	}
	soCamVB = camArrayVB.length;
	echo("soCamVB: "+soCamVB);
}
/*
//for Test in flash (without VB)
splitCam();
setCam();
*/
fscommand("", "load");
